<?php /*
	*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}

////////////////////////############## INSERT into database. ###############///////////////////
$msg= "";	
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")
{				
				$manuf=mysql_real_escape_string($_REQUEST['manuf']);
				$cat=mysql_real_escape_string($_REQUEST['parentId']);
				$proid=mysql_real_escape_string($_REQUEST['proid']);
				$qty=mysql_real_escape_string($_REQUEST['proqty']);
				$model=mysql_real_escape_string($_REQUEST['promodel']);
				$varthpath = $_FILES['imagefile']['name'];
				$price=mysql_real_escape_string($_REQUEST['proprice']);
				$weight=0.00;
				if(isset($_REQUEST['proweight']) && ($_REQUEST['proweight'])!="")
				{
				$weight=mysql_real_escape_string($_REQUEST['proweight']);
				}else{$weight=0.00;}
				$contid=0;
				$sql="SELECT max( intordered ) AS max
						FROM `tblproducts` ";
				$result=$obj_db->select($sql);	
				if($result)
				{
					$contid=$result[0]['max'];
					$contid++;
				}
			if(($_FILES['imagefile']['size'] > 2000000))
			{
				echo $_FILES['imagefile']['size'];						
				header("location:product.php?msg=imgszbg");
				die();
			}
			else
			{
				if(isset($_SESSION['adminuserid']))
				{
					$edit=$_SESSION['adminuserid'];
				}
				
				
				$insert="INSERT INTO `tblproducts` (`intprodid`,`intmanufacture`,`intcategoryid`,`intprodquantity`,`intprodmodel`,`intproddefaultimg`,`decprice`,`dtaddeddate`,`dtlastmodified`,`dtavailable`,`decprodweight`,`intstatus`,`intordered`,`varedited`) VALUES ('$proid','$manuf','$cat','$qty','$model','$varthpath','$price',NOW(),NOW(),NOW(),'$weight','0','$contid','$edit')";
				$sql=$obj_db->insert($insert);
				
				###################################
				// Product Attribute
				###################################
				
				if(isset($_REQUEST['option']) && ($_REQUEST['option'])!='')
				{
					$option=$_REQUEST['option'];
					$price=$_REQUEST['price'];
					$prifix=$_REQUEST['prifix'];
					
					for($s=0;$s<count($_REQUEST['option']);$s++) {
						$option1=$option[$s];
						$optnew=explode("||",$option1);
						$opt=$optnew[1];
						$vql=$optnew[0];
						$arrayitem=$optnew[2];
						$price1=$price[$arrayitem];
						$prifix1=$prifix[$arrayitem];
		$insert123 = "INSERT INTO `tblproductattributes` (`intproductid`, `intoptionid`, `intoptionvalueid`, `decprice`, `charprefix`) VALUES ('$proid',$opt,$vql,$price1,'$prifix1')";	
						$sql12=$obj_db->insert($insert123);
					}
					
				}
				// Image uploading
				if(isset($_REQUEST['uploading']) && trim($_REQUEST['uploading']) == "imageupload" && $_FILES['imagefile']['name']!="") {
					$targetpath = "../images/product/";
					$ext=$_FILES['imagefile']['name'];
					$ext=explode(".",$ext);
					if($ext[1]=="jpg" || $ext[1]=="gif" || $ext[1]=="jpeg" || $ext[1]=="png" || $ext[1]=="bmp" || $ext[1]=="wbmp" || $ext[1]=="JPEG" || $ext[1]=="JPG")	{
						if($_FILES['imagefile']['size'] <= 2000000) {
							$filename=$targetpath.$ext[0].$proid.".".$ext[1];
							$fl_db=$ext[0].$proid.".jpg";
							if(file_exists($filename)) {
								chmod($filename, 0777);
								unlink($filename);
							}
							if(move_uploaded_file($_FILES['imagefile']['tmp_name'],$filename)) {
								$targetpath = "../images/product/big/";
								$file=createThumb($filename , $targetpath , $ext[0].$proid , $_SESSION['config_val'][0]['intproductbigimage']);
								$targetpath = "../images/product/midium/";
								$file=createThumb($filename , $targetpath , $ext[0].$proid , $_SESSION['config_val'][0]['intmidiumimg']);
								$targetpath = "../images/product/";
								$file=createThumb($filename , $targetpath , $ext[0].$proid , $_SESSION['config_val'][0]['intproductthimage']);
								$sql= "UPDATE tblproducts SET intproddefaultimg = '".$fl_db."' WHERE intprodid = '".$proid."' ";
								$res=$obj_db->sql_query($sql);
							}
						} else {
							header("location:product.php?msg=imgszbg");
							die();
						}
					}
				}
				
				//$proid=$screen_id;
				$sql="select * from tbllanguages";
				$res=$obj_db->select($sql);
				if(count($res)>0)
				{
					for($l=0;$l<count($res);$l++)
					{
					$lid=$res[$l]['intlangaugeid'];
					$liid="language_".$lid;
						if(isset($_REQUEST[$liid]) && ($_REQUEST[$liid])!="") {
							$proname = mysql_real_escape_string($_REQUEST[$liid]);
							$desc=mysql_real_escape_string(str_replace("\r\n","<br />",$_REQUEST['desc']));
							$sql1="INSERT INTO `tblproddesc` (`intid`, `intlanguageid` , `varprodname` , `txtdesc`,`intprodviewed`) VALUES ('$proid', '$lid', '$proname', '$desc','0')";
							$insert=$obj_db->insert($sql1);						
						}
					}
				}
			}
			header("location:product.php?msg=add");
			die();
}	
	
////////////////////////############## End of INSERT into database.###############///////////////////

/////////////// ######################## UPDATE the record ######################### ////////////////
$p_manuf="";
$p_cat="";
$p_pid="";
$p_qty="";
$p_model="";
$p_price="";
$p_weight="";
$p_tax="";
$action=1;
if((isset($_REQUEST['a']) && trim($_REQUEST['a'])==2) && (!(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")))
{
	
 	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid'])!="")
 	{
		$screen_id =  $_REQUEST['intid'];
		$sql = "select * from tblproducts where intprodid ='$screen_id'";
		
		$result = $obj_db->select($sql);
		if(count($result)<=0)
		{
			echo " No Record Found!<br>";
			die();
		}
		if($result)
		{
			foreach($result as $row)
			{
				$p_manuf=stripslashes($row['intmanufacture']);
				$p_cat=stripslashes($row['intcategoryid']);
				$p_pid=stripslashes($row['intprodid']);
				$p_qty=stripslashes($row['intprodquantity']);
				$p_model=stripslashes($row['intprodmodel']);
				$p_price=stripslashes($row['decprice']);
				$p_weight=stripslashes($row['decprodweight']);
				$p_ed=stripslashes($row['varedited']);
				$action=2;
			}
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Update")
		{
				$proid=mysql_real_escape_string($_REQUEST['proid']);
				$manuf=mysql_real_escape_string($_REQUEST['manuf']);
				$cat=mysql_real_escape_string($_REQUEST['parentId']);
				$qty=mysql_real_escape_string($_REQUEST['proqty']);
				$model=mysql_real_escape_string($_REQUEST['promodel']);
				$varthpath = $_FILES['imagefile']['name'];
				$price=mysql_real_escape_string($_REQUEST['proprice']);
				$weight=mysql_real_escape_string($_REQUEST['proweight']);
				
			if(($_FILES['imagefile']['size'] > 2000000))
			{					
				header("location:product.php?msg=imgszbg");
				die();
			} else {
				if(isset($_SESSION['adminuserid']))
				{
					$edit=$_SESSION['adminuserid'];
				}
				$sql_upd ="UPDATE tblproducts SET 
						intmanufacture = '$manuf',
						intcategoryid = '$cat',
						intprodid='$proid',
						intprodquantity = '$qty',
						intprodmodel = '$model',
						decprice = '$price',
						decprodweight = '$weight',
						dtaddeddate=dtaddeddate,
						dtlastmodified=NOW(),
						dtavailable=NOW(),
						varedited='$edit'
						where intprodid ='$screen_id'"; 
				$result1 = $obj_db->sql_query($sql_upd);
				
				$sql="select * from tbllanguages";
				$res=$obj_db->select($sql);
				if(count($res)>0)
				{
					for($l=0;$l<count($res);$l++)
					{
					$lid=$res[$l]['intlangaugeid'];
					$liid="language_".$lid;
					
						if(isset($_REQUEST[$liid]) && ($_REQUEST[$liid])!="")
						{
						if(isset($_REQUEST['proid']) && ($_REQUEST['proid'])!="")
						{
							$proid=$_REQUEST['proid'];
						}
						$proname = mysql_real_escape_string($_REQUEST[$liid]);
						$desc=mysql_real_escape_string(str_replace("\r\n","<br />",$_REQUEST['desc']));
						$sql2="UPDATE tblproddesc SET intid='$proid',varprodname = '$proname',txtdesc='$desc' WHERE intid = '$screen_id'";
						$obj_db->sql_query($sql2);
						}
					}
				}
				$del="delete from tblproductattributes where intproductid='$screen_id'";
				$delatt=mysql_query($del);
				
				if(isset($_REQUEST['option']) && ($_REQUEST['option'])!='')
				{
					$option=$_REQUEST['option'];
					$price=$_REQUEST['price'];
					$prifix=$_REQUEST['prifix'];
					
					for($s=0;$s<count($_REQUEST['option']);$s++) {
						$option1=$option[$s];
						$optnew=explode("||",$option1);
						$opt=$optnew[1];
						$vql=$optnew[0];
						$arrayitem=$optnew[2];
						$price1=$price[$arrayitem];
						$prifix1=$prifix[$arrayitem];
		$insert123 = "INSERT INTO `tblproductattributes` (`intproductid`, `intoptionid`, `intoptionvalueid`, `decprice`, `charprefix`) VALUES ('$proid',$opt,$vql,$price1,'$prifix1')";	
						$sql12=$obj_db->insert($insert123);
					}
					
				}
				$action=1;
				
				// update images
				if(isset($_REQUEST['uploading']) && trim($_REQUEST['uploading']) == "imageupload" &&$_FILES['imagefile']['name']!="") {
						$targetpath = "../images/product/";
						$ext=$_FILES['imagefile']['name'];
						$ext=explode(".",$ext);
						if($ext[1]=="jpg" || $ext[1]=="gif" || $ext[1]=="jpeg" || $ext[1]=="png" || $ext[1]=="bmp" || $ext[1]=="wbmp" || $ext[1]=="JPEG" || $ext[1]=="JPG") {
						if($_FILES['imagefile']['size'] <= 2000000)	{
						$filename=$targetpath.$ext[0].$proid.".".$ext[1];
						$fl_db=$ext[0].$proid.".jpg";
						// delete from folder
						$sqldel = "SELECT intproddefaultimg FROM tblproducts WHERE intprodid = '$screen_id'";
						$resultdel = $obj_db->sql_query($sqldel);
							if(count($resultdel)>0)
							{
								for($i=0;$i<count($resultdel);$i++)
								{
									$targetpath1 = "../images/product/midium/";
									$targetpath2 = "../images/product/big/";
									$targetpath3= "../images/product/";
									$th_file = $resultdel[$i]['intproddefaultimg'];
									$filename1=$targetpath1.$th_file;
									$filename2=$targetpath2.$th_file;
									$filename3=$targetpath3.$th_file;
									if(file_exists($filename2))	{
										chmod($filename1, 0777);
										unlink($filename1);
										chmod($filename2, 0777);
										unlink($filename2);
										chmod($filename3, 0777);
										unlink($filename3);
									}
								}
							}
						
						if(move_uploaded_file($_FILES['imagefile']['tmp_name'],$filename)) {
						
						$targetpath = "../images/product/big/";
						$file=createThumb($filename , $targetpath , $ext[0].$proid , $_SESSION['config_val'][0]['intproductbigimage']);
						$targetpath = "../images/product/midium/";
						$file=createThumb($filename , $targetpath , $ext[0].$proid , $_SESSION['config_val'][0]['intmidiumimg']);
						$targetpath = "../images/product/";
						$file=createThumb($filename , $targetpath , $ext[0].$proid , $_SESSION['config_val'][0]['intproductthimage']);					
						$sql= "UPDATE tblproducts SET intproddefaultimg = '".$fl_db."' WHERE intprodid = '".$proid."' ";
						$res=$obj_db->sql_query($sql);
						}
						} else {
							header("location:product.php?msg=imgszbg");
							die();
						}
						}
					}
				
			}
		if(isset($_REQUEST['ser']) && ($_REQUEST['ser'])=='on')
		{
		if(isset($_REQUEST['select']) && ($_REQUEST['select'])!=0 && !isset($_REQUEST['select2']))
		{
			$manu= $_REQUEST['select'];
			header("location:product.php?msg=edit&select=$manu&ser=on");
		    die();
		}
		}	
		if(isset($_REQUEST['ser']) && ($_REQUEST['ser'])=='on')
		{
		if(isset($_REQUEST['select2']) && ($_REQUEST['select2'])!=0 && !isset($_REQUEST['select']))
		{
			$cat= $_REQUEST['select2'];
			header("location:product.php?msg=edit&select2=$cat&ser=on");
		    die();
		}	
		}
		if(isset($_REQUEST['ser']) && ($_REQUEST['ser'])=='on')
		{
		if((isset($_REQUEST['select']) && ($_REQUEST['select'])!=0) && (isset($_REQUEST['select2']) && ($_REQUEST['select2'])!=0))
		{
			$manu= $_REQUEST['select'];
			$cat= $_REQUEST['select2'];
		    header("location:product.php?msg=edit&select2=$cat&ser=on&select=$manu");
		    die();
		}
		} else {
		header("location:product.php?msg=edit");
		die();
		}			
			
}

}

}

}

///////////// ######################## End of UPDATE the record ######################### /////////////



////// ############### DELETE record from database ############### ///////////////////

if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3)
{
	
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!=""))
	{	
		$id =  mysql_real_escape_string($_REQUEST['intid']);
		$sql= "DELETE FROM `tblproducts` WHERE `intprodid` ='$id'";
		$query1 = mysql_query($sql);
		$sql4="delete from `tblproddesc` where `intid`='$id'";
		$delete1=mysql_query($sql4);
		$sql5="delete from `tblproimages` where `intprodid`='$id'";
		$delete2=mysql_query($sql5);
		
		header("location:product.php?msg=del");
		die();
	}
}
////// ############### End of DELETE record from database ############### ///////////////////


////////////// UP Sorting //////////////////////
if(isset($_REQUEST['action']) && trim($_REQUEST['action'])==6)
{
  $sortno=$_REQUEST['sort'];
  $sorttmp="";
  $sql="select * from tblproducts";
		   $sql_link=$obj_db->select($sql);
  
   			for($i=0;$i<count($sql_link);$i++)
   				{
					if($sql_link[$i]['intordered'] < $sortno )
					{
						$sorttmp= $sql_link[$i]['intordered'];
					}
				}
				
				$sql="UPDATE `tblproducts` SET 
				`intordered` = '".$sortno."',
				`dtaddeddate` = dtaddeddate
				WHERE `intordered` =".$sorttmp;
				
				 $result=$obj_db->edit($sql);	
				 
				$sql="UPDATE `tblproducts` SET 
				`intordered` = '".$sorttmp."',
				`dtaddeddate` = dtaddeddate
				 WHERE `intprodid` =".$_REQUEST['fid'];

			  $result=$obj_db->edit($sql);	
			header("Location:product.php");
			die();
				

}
if(isset($_REQUEST['action']) && trim($_REQUEST['action'])==7)
{
	$sortno=$_REQUEST['sort'];
  $sorttmp="";
  $sql="select * from tblproducts";
		   $sql_link=$obj_db->select($sql);
  			$cond=true;
   			for($i=0;$i<count($sql_link);$i++)
   				{
					if($sql_link[$i]['intsortorder'] > $sortno && $cond==true)
					{
						$sorttmp= $sql_link[$i]['intsortorder'];
						$cond=false;
					}
				}
				
				$sql="UPDATE `tblproducts` SET 
				`intordered` = '".$sortno."',
				`dtaddeddate` = dtaddeddate
				WHERE `intordered` =".$sorttmp;
				
				 $result=$obj_db->edit($sql);	
				 
				$sql="UPDATE `tblproducts` SET 
				`intordered` = '".$sorttmp."',
				`dtaddeddate` = dtaddeddate
				 WHERE `intprodid` =".$_REQUEST['fid'];

			  $result=$obj_db->edit($sql);	
			header("Location:product.php");
			die();
				

}

?>
<script language="javascript">
function check()
{
	
	var cond=true;
	if(document.prod.manuf.value==0)
	{
		alert("Please Select Manufacture.");
		if(cond==true)
		{
			document.prod.manuf.focus();
		}
		cond=false;
		return false;
	}	
	if(document.prod.proqty.value.length==0)
	{
		alert("Please enter Product Quantity.");
		if(cond==true)
		{
			document.prod.proqty.focus();
		}
		cond=false;
		return false;
	}	
	if(document.prod.promodel.value.length==0)
	{
		alert("Please enter Product Model.");
		if(cond==true)
		{
			document.prod.promodel.focus();
		}
		cond=false;
		return false;
	}	
	if(document.prod.proprice.value.length==0)
	{
		alert("Please enter Product Price.");
		if(cond==true)
		{
			document.prod.proprice.focus();
		}
		cond=false;
		return false;
	}	
	if(document.prod.tax.value==0)
	{
		alert("Please Select Tax Class.");
		if(cond==true)
		{
			document.prod.tax.focus();
		}
		cond=false;
		return false;
	}	
}	
</script>
<?php include("inc/header.php");?>
<body>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td width="2%">&nbsp;</td>
    <td width="96%">
	<?php
	
if(isset($_REQUEST['script']))
{
	if(trim($_REQUEST['script'])=='addproduct' || trim($_REQUEST['script'])=='editproduct')
	{
	
	?>
	  <form name="prod" action="" enctype="multipart/form-data" method="post">	
      <table width="80%" align="center" cellpadding="2" cellspacing="2" class="border">
        <tr class="bg1">
          <td align="center"><strong>
		  
     <?php
	 
	 if($_REQUEST['script']=='addproduct'){echo "Add Product...";}
	if($_REQUEST['script']=='editproduct'){echo "Edit Product...";}
	
	?>
          </strong></td>
        </tr>
        <tr >
          <td><table width="100%"  border="0" align="center" cellpadding="2" cellspacing="2">
              <tr>
                <td width="16%">&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td align="right">(* All fields are Compulsory)</td>
              </tr>
              <tr>
                <td align="right" class="sltimg">*Manufacture </td><td>:</td>
                <td><select name="manuf" id="manuf">
                    <option value="0">Select Manufacturer</option>
                    <?php 
						$sql="select * from tblmanufactures";
						$resman = $obj_db->select($sql);
						if(count($resman)>0)
						{
							for($m=0;$m<count($resman);$m++)
							{						
					?>
					<option value="<?php echo $resman[$m]['intmanufactureid'];?>"<?php if($resman[$m]['intmanufactureid'] == $p_manuf){echo "selected";}else{echo "";} ?>><?php echo $resman[$m]['varname'];?></option>
					<?php 
							}
						}
					?>
                </select></td>
              </tr>
              <tr>
                <td align="right" class="sltimg">*Category</td>
                <td>:</td>
                <td>
                  <select name="parentId" id="parentId">
                  <option value="0">Root</option>
                  <?php 
					if($action == 2)
					{
						$selected = $p_cat;
					}else{
						$selected = 0;
					}	
					echo GetChild(0,0,$selected,$obj_db,1);
				?>
              </select>               </td>
              </tr>
              
              <tr>
                <td align="right" class="sltimg">Product Id  </td>
                <td>:</td>
                <td><input name="proid" type="text" id="proid" value="<?php echo $p_pid;?>"/></td>
              </tr>
              <tr>
                <td align="right" class="sltimg">*Product Quantity </td>
                <td>:</td>
                <td><input name="proqty" type="text" id="proqty" value="<?php echo $p_qty;?>"/></td>
              </tr>
              
              <tr>
                <td align="right" class="sltimg">*Product Model </td>
                <td>:</td>
                <td><input name="promodel" type="text" id="promodel" value="<?php echo $p_model;?>"/></td>
              </tr>
              <tr>
                <td align="right" class="sltimg">*Product Image </td>
                <td>:</td>
                <td>
                    <input name="imagefile" type="file" id="imagefile" /></td>
              </tr>
              <tr>
                <td align="right" class="sltimg">*Product Price</td>
                <td>:</td>
                <td><input name="proprice" type="text" id="proprice" value="<?php echo $p_price;?>"/></td>
              </tr>
              <tr>
                <td align="right" class="sltimg">Product Weight </td>
                <td>:</td>
                <td><input name="proweight" type="text" id="proweight" value="<?php echo $p_weight;?>"/></td>
              </tr>
			  <?php
            $sql="select * from tbllanguages";
			$res=$obj_db->select($sql);
			if(count($res)>0)
			{
				for($l=0;$l<count($res);$l++)
				{
				$lid=$res[$l]['intlangaugeid'];
				$liid="language_".$lid;
				
			?>
              <tr>
                <td align="right" class="sltimg">*Product Name(<?php echo stripslashes($res[$l]['varcode']);?>)</td>
                <td>:</td>
				<?php			  
				if(isset($screen_id) && isset($screen_id)!="")
			  	{	
					$sql="select * from `tblproddesc` WHERE `intid`='$screen_id'";
					$resman = $obj_db->select($sql);
					if(count($resman)>0)
					{			  
			  ?>
                <td><input type="text" name="<?php echo $liid;?>" onBlur="if(this.value=='') {alert('Please enter Product name'); return false;}" value="<?php echo stripslashes($resman[0]['varprodname']);?>"/></td>
              </tr>
			  
              <tr>
                <td align="right" valign="top" class="sltimg">*Product Description(<?php echo $res[$l]['varcode'];?>)</td>
                <td valign="top">:</td>
                <td>
                  <textarea name="desc" cols="35" rows="05" onBlur="if(this.value=='')	{alert('Please enter Product Description'); return false;}"><?php echo str_replace("<br />","\r\n",stripslashes($resman[0]['txtdesc']));?></textarea>                </td>
				<?php 
					}}
					else
					{
				?>
				<td width="28%"><input type="text" name="<?php echo $liid;?>" onBlur="if(this.value=='')	{alert('Please enter Product name'); return false;}"/></td>
			  </tr>
			  
              <tr>
                <td align="right" valign="top" class="sltimg">*Product Description(<?php echo $res[$l]['varcode'];?>)</td>
                <td valign="top">:</td>
                <td>
                  <textarea name="desc" cols="35" rows="05" onBlur="if(this.value=='')	{alert('Please enter Product Description'); return false;}"></textarea>                </td>
				<?php } ?></tr>
			  <?php 
			  }}
			  ?>
              <tr>
                <td colspan="3" align="left" class="sltimg"> &nbsp;&nbsp;&nbsp;Product Attributes </td>
                </tr>
				 
				<?php 
				$arrcount=0;
			$sql6="select * from tbloptionvalues";
			$resatt=$obj_db->select($sql6);
			if(count($resatt)>0)
			{
				for($a=0;$a<count($resatt);$a++)
				{
				$opid=$resatt[$a]['intid'];
			?>
               
               <tr>
                  <td align="right" class="sltimg">&nbsp;</td>
                  <td class="sltimg">&nbsp;</td>
                  <td class="sltimg">&nbsp;</td>
                </tr>
                <tr>
                <td align="right" valign="top" class="sltimg"><?php 
				
				echo stripslashes($resatt[$a]['varoptionvaluename']);
				
				$sql451="select * from tblproductoptions where intoptionid=$opid";
				$res451=$obj_db->select($sql451);
				if(count($res451)>0) {
				?></td>
                <td valign="top" class="sltimg">:</td>
                <td class="sltimg"> <?php 
				for($o=0;$o<count($res451);$o++)
				{
				$propid=$res451[$o]['intid'];
				?>
				<br />
				<input name="option[]" type="checkbox" id="option[]" value="<?php echo $res451[$o]['intid']."||".$opid."||".$arrcount;?>"  <?php
				$arrcount++;
				$optionvalueid="";
				if(isset($screen_id)) {
					$sqlop="select * from tblproductattributes where intproductid='$screen_id'";
					$resop=$obj_db->select($sqlop);
					if(count($resop)>0)	{
						for($k=0;$k<count($resop);$k++)	{
							$optionvalueid=$resop[$k]['intoptionvalueid'];
							if($optionvalueid==$res451[$o]['intid']) {
								echo "checked=\"checked\"";
							}
						}
					}
				}
				?>/>
				<?php echo stripslashes($res451[$o]['varoptionname']);?>
				<?php
				$decprice="";
				$charprefix="";
				if(isset($screen_id)) {
				$sqlop="select * from tblproductattributes where intproductid='$screen_id' and intoptionvalueid=$propid";
				$resop=$obj_db->select($sqlop);
					if(count($resop)>0)	{
						$decprice=$resop[0]['decprice'];
						$charprefix = $resop[0]['charprefix'];
					}
				}?>
				<br />
				<input name="price[]" type="text" id="price" size="5" value="<?php echo $decprice; ?>" />
				<input name="prifix[]" type="text" id="prifix" size="5"  value="<?php echo $charprefix; ?>"/>
				(&nbsp;Price Effector,Prefix(+/-))
				<?php } ?></td>
                </tr>
			  <?php 
			  }}}
			  ?>
              <tr>
                <td><input type="hidden" name="uploading" value="imageupload" /></td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td colspan="3" align="center"><input name="Submit" type="submit" class="btn" 
				 value="<?php echo ($action==2) ? "Update":"Submit"; ?>" onClick="return check();" />                </td>
              </tr>
          </table></td>
        </tr>
      </table></form>
    <?php
	}
}
else
{
?>
   
			
	<table width="100%" border="0" align="center" cellpadding="1" cellspacing="0" class="border">
	
      <tr class="bg1">
        <td ><table width="100%" border="0" align="center" cellpadding="1" cellspacing="0">
            <tr align="center" class="line_top">
              <td width="100%" align="left">Products...</td>
              <td width="100%" align="right" class="line_top"><a class="aa" href="product.php?script=addproduct">[NEW]</a> </td>
            </tr>
        </table></td>
      </tr>
      <tr>
        <td class="box">
		
		<table width="100%"  border="0" align="center" cellpadding="2" cellspacing="2">
            <tr>
              <td colspan="13" align="left"><strong>Row per Page:</strong></td>
            </tr>
            <tr>
               <?php 
	   $rows="";
	 if(isset($_REQUEST['page']) && ($_REQUEST['page'])!="")
	 {
	 	$rows=$_REQUEST['page'];
	 
	  }	
	  ?><form name="form1" action="" method="post">
              <td colspan="13" align="left"><select name="page" onChange="document.form1.submit();">
                  <option value="0"<?php if($rows=='0'){echo "selected";}else{echo "";}?>>All</option>
                  <option value="5"<?php if($rows=='5'){echo "selected";}else{echo "";}?>>5 Per Page</option>
                  <option value="10"<?php if($rows=='10'){echo "selected";}else{echo "";}?>>10 Per Page</option>
                  <option value="15"<?php if($rows=='15'){echo "selected";}else{echo "";}?>>15 Per Page</option>
                </select>				</td></form>
              </tr>
            <tr>
              <td colspan="13" align="center"><form action="product.php?ser=on" method="post" name="serch" id="serch">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td colspan="2" align="left" class="seprtr">&nbsp;</td>
                    </tr>
                  <tr>
                    <td height="20" align="left"><strong>Search:</strong></td>
                    <td>&nbsp;</td>
                  </tr>
                  <tr>
                    <td width="73%" height="20" align="left"><select name="select" id="select">
                          <option value="0">Select Manufacturer</option>
                          <?php 
						$sql="select * from tblmanufactures";
						$resman = $obj_db->select($sql);
						if(count($resman)>0)
						{
							for($m=0;$m<count($resman);$m++)
							{		
							   $mid= $resman[$m]['intmanufactureid'];				
					?>
                          <option value="<?php echo $resman[$m]['intmanufactureid'];?>"<?php if($resman[$m]['intmanufactureid'] == $p_manuf){echo "selected";}else{echo "";} ?>>
                          <?php echo $resman[$m]['varname'];?>
                          </option>
                          <?php 
							}
						}
					?>
                        </select>
                      &nbsp;&nbsp;
                      <?php 
	if(isset($_REQUEST['select']) && ($_REQUEST['select'])!="")
	{
		$manu= $_REQUEST['select'];
		//echo $manu;
	}
	?>
                      <select name="select2" id="select2">
                        <option value="0">Root</option>
                        <?php 
					if($action == 2)
					{
						$selected = $p_cat;
						
						
					}else{
						$selected = 0;
					}	
					echo GetChild(0,0,$selected,$obj_db,1);
				?>
                      </select>
                      <?php if(isset($_REQUEST['select2']) && ($_REQUEST['select2'])!="")
	{
		$cat= $_REQUEST['select2'];
		//echo $cat;
	} ?>
                      &nbsp;&nbsp;&nbsp;&nbsp; <strong>Product Id:
                      <input name="productid" type="text" id="productid" size="10" />
                      </strong></td>
                    <td width="27%"><input name="Submit" type="submit" class="btn" id="Submit" value="Go" /></td>
                  </tr>
                </table>
              </form></td>
              </tr>
            <tr class="tblbg3">
			<td align="center"><strong>Product No </strong> </td>
              <td align="center"><?php 
			if(isset($_REQUEST['sort']) && ($_REQUEST['sort'])=='alphaasc')
			{
			?>
			<a  class="ab1" href="product.php?sort=alphadesc">Name</a>
			<?php 
				}
				else if(isset($_REQUEST['sort']) && ($_REQUEST['sort'])=='alphadesc')
				{
			?><a class="ab1" href="product.php?sort=alphaasc">Name</a>
			<?php }
				else
				{
				 ?>
			 <a class="ab1" href="product.php?sort=alphadesc">Name</a>
			 <?php
		 }?></td>
              <td align="center"><strong>Image</strong> </td>
			  <td align="center"><strong>Add Specials</strong> </td>
			  <td align="center"><strong>Images</strong> </td>
			  <td align="center"><strong>Add to gift idea</strong></td>
			  <td align="center"><strong>Add related product</strong> </td>
			  <td align="center"><strong>Status</strong> </td>
			  <td align="center"><strong>Asending</strong> </td>
			  <td align="center"><strong>Desending</strong> </td>
			  <td align="center"><strong>Edited By</strong> </td>
              <td align="center"><strong>Edit</strong></td>
              <td align="center"><strong>Delete</strong></td>
            </tr>
            <?php
	
	// change status disable or active
if(isset($_REQUEST['status']))
{
	if(isset($_REQUEST['s']) && trim($_REQUEST['s'])==0)
	 {
		if(isset($_REQUEST['pid']) && trim($_REQUEST['pid']!=""))
		{
			$id=$_REQUEST['pid'];
			$update = $obj_db->sql_query("update tblproducts set intstatus = 1 where intprodid='$id'");
			header("location:product.php");
			die();
		}
	}
	if(isset($_REQUEST['s']) && trim($_REQUEST['s'])==1)
	{
		if(isset($_REQUEST['pid']) && trim($_REQUEST['pid']!=""))
		{
			$id=$_REQUEST['pid'];
			$update = $obj_db->sql_query("update tblproducts set intstatus = 0 where intprodid='$id'");
			header("location:product.php");
			die();
		}
	}
}
		/**************************************
				PAGING CODE START
		**************************************/
		$rowperpage=20;
		if(isset($_REQUEST['page']) && ($_REQUEST['page'])!=0)
			{
				$rows=$_REQUEST['page'];
				$rowperpage=$rows;
			}else{$rowperpage=$rows=20;}
		$tablename="tblproducts";
		$per_page_keywords= "";
		$per_page_sorts="";
		include("system/paging.inc.php");

		/**************************************
				PAGING CODE ENDING
		**************************************/

	
		/*if(isset($_REQUEST['Submit']) && ($_REQUEST['Submit'])=='Go')
		{
			if(isset($_REQUEST['search']) && trim($_REQUEST['search'])!="")
			{
				
				$src= $_REQUEST['search'];
				echo $src;
				
			}
		}	*/
	$que="";	
	if(isset($_REQUEST['ser']) && ($_REQUEST['ser'])=="on")
	{
	//if(isset($_REQUEST['Submit']) && ($_REQUEST['Submit'])=='Go')
	{
	
	$proid="";
	$conditionsrch=false;
	$wherequerydet=" ";
	if(isset($_REQUEST['productid']) && ($_REQUEST['productid'])!="")
	{
		$proid=$_REQUEST['productid'];
		//$que.=" intprodid LIKE '%".$proid."%' OR ";
		if($conditionsrch==true)
			{
				$wherequerydet .=" AND ";
			}
			$wherequerydet .="  intprodid LIKE '%".$_REQUEST['productid']."' ";
	$conditionsrch=true;
	}
	
	if(isset($_REQUEST['select']) && ($_REQUEST['select'])!=0)
	{
		$manu= $_REQUEST['select'];
		
		//$que.="intmanufacture='$manu'";
		if($conditionsrch==true)
			{
				$wherequerydet .=" AND ";
			}
			$wherequerydet .="  intmanufacture='".$_REQUEST['select']."' ";
	$conditionsrch=true;
	}
	
	if(isset($_REQUEST['select2']) && ($_REQUEST['select2'])!=0)
	{
		$cat= $_REQUEST['select2'];
		/*if($cond==true)
		{
		$que.=" AND ";
		}
		$que.=" intcategoryid='$cat'";*/
		if($conditionsrch==true)
			{
				$wherequerydet .=" AND ";
			}
			$wherequerydet .="  intcategoryid='".$_REQUEST['select2']."' ";
	$conditionsrch=true;
	}
	$cond=true;	
	$sql_select = "select * from tblproducts where ".$wherequerydet."";
	//	echo $sql_select; die();
	$sql = $obj_db->select($sql_select);
	//print_r($sql);
	if($sql)
	{
	//$i=0;
	for($j=0;$j<count($sql);$j++)
	 { 
		$proid=$sql[$j]['intprodid'];
		//echo $proid;
		 //$i=$i+1;
		  ?>
            <tr class="<?php echo ($j%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';" onMouseOut="this.className='<?php echo ($j%2==0)?"Hrnormal":"Hralter"; ?>';">			<td align="center"><?php echo $proid;?></td>
              <td align="center">
			  <?php
			  $sql6="select * from tblproddesc where intid = '$proid'"; 
			  $resname = $obj_db->select($sql6);
			  if(count($resname)>0)
			  {
			  	for($pn=0;$pn<count($resname);$pn++)
				{
					echo stripslashes($resname[$pn]['varprodname']);
			  ?>			  </td>
              <td align="center"><img src="../images/product/<?php echo $sql[$j]['intproddefaultimg'];?>" title="'<?php echo $resname[$pn]['varprodname'];?>'" alt="<?php echo $resname[$pn]['varprodname'];?>"/></td>
			  
			  
			  
			  <td align="center"><a Title="Click here to Add Product to Specials" href="addtospecial.php?proid=<?php echo $proid;?>" class="ab">Add Specials</a></td>
			  <td align="center"><a Title="Click here to see Product Images" href="productimages.php?proid=<?php echo $proid;?>" class="ab">Images</a></td>
			  <td align="center"><a Title="Click here to view Gift Ideas" href="addtogift.php?proid=<?php echo $proid;?>" class="ab">Add to Gift Idea</a></td>
			  <td align="center"><a Title="Click here to Add Product Related Products" href="addtorelated.php?proid=<?php echo $proid;?>" class="ab">Add Related Product</a></td>
			  
			  <?php 
			  	}
			  }
			  ?>
			  
			  <td align="center"><table border="0" cellspacing="0" cellpadding="0" align="center">
				  <tr>
		<?php 
					if($sql[$j]['intstatus']==0)
					{
						
						echo "<td><a Title='Click here to Show Product' class='aa' href='product.php?status=0&s=0&pid=$proid'>Show</a></td>";		
					}
					if($sql[$j]['intstatus']==1)
					{
						
						echo "<td><a Title='Click here to Hide Product' class='aa' href='product.php?status=1&s=1&pid=$proid'>Hide</a></td>";
					}
				?>
				</tr></table></td>
				<td><a href="product.php?fid=<?php echo $sql[$j]['intprodid'];?>&action=6&sort=<?php echo $sql[$j]['intordered'];?>" class="aa">Ascending</a></td>
				<td><a href="product.php?fid=<?php echo $sql[$j]['intprodid'];?>&action=7&sort=<?php echo $sql[$j]['intordered'];?>" class="aa">Descending</a></td>
				<td align="center"><?php 
				$adm=$sql[$j]['varedited'];
				$sqla="select varadminfname from tbladmin where intid='$adm'";
				$resa=$obj_db->select($sqla);
				echo $resa[0]['varadminfname'];
				?></td>
              <td align="center">
			  <?php 
			    if(isset($_REQUEST['select']) && ($_REQUEST['select'])!=0)
				{
					$manu= $_REQUEST['select'];
				}	
				if(isset($_REQUEST['select2']) && ($_REQUEST['select2'])!=0)
				{
					$cat= $_REQUEST['select2'];
				}	
			  ?>
			  <a class="link" Title="Click here to Edit" href="product.php?script=editproduct&amp;a=2&amp;intid=<?php echo $proid;?><?php if(isset($_REQUEST['ser']) && ($_REQUEST['ser'])=='on'){if(isset($_REQUEST['select']) && ($_REQUEST['select'])!=0){echo "&ser=on&select=$manu";}if(isset($_REQUEST['select2']) && ($_REQUEST['select2'])!=0){echo "&ser=on&select2=$cat";} if((isset($_REQUEST['select']) && ($_REQUEST['select'])!=0) && (isset($_REQUEST['select2']) && ($_REQUEST['select2']))){ echo "&ser=on&select2=$cat&select=$manu";}}?>"><img src="images/edit.bmp" border="0"/></a></td>
              <td align="center"><a Title="Click here to Delete" class="link" href="product.php?a=3&amp;intid=<?php echo $proid;?>" onClick="return confirm('Are you sure to delete this record ?');"><img src="images/delete.bmp" border="0"/></a></td>
            </tr>
            <?php 
		}
		?>
            <tr >
              <td colspan="13" ><div align="center">
                  <?php
?>
              </div></td>
            </tr>
            <?php
	}	
   ?>
        </table>
		
		
		</td>
      </tr>
    </table>
    <?php
	}	
	
	}
	else 
	{
	if(isset($_REQUEST['sort']) && ($_REQUEST['sort'])=='alphaasc')
	{
	$sql_select = "select tblproducts.*, tblproddesc.varprodname from tblproducts,tblproddesc where tblproducts.intprodid=tblproddesc.intid ORDER BY tblproddesc.varprodname ASC Limit ".($page_no*$row_per_page).",".$row_per_page;
	}
	else if(isset($_REQUEST['sort']) && ($_REQUEST['sort'])=='alphadesc')
	{
	$sql_select = "select tblproducts.*, tblproddesc.varprodname from tblproducts,tblproddesc where tblproducts.intprodid=tblproddesc.intid ORDER BY tblproddesc.varprodname DESC Limit ".($page_no*$row_per_page).",".$row_per_page;
	}
	else
	{
	$sql_select = "select tblproducts.*, tblproddesc.varprodname from tblproducts,tblproddesc where tblproducts.intprodid=tblproddesc.intid ORDER BY tblproducts.intordered ASC Limit ".($page_no*$row_per_page).",".$row_per_page;
	}
	$sql = $obj_db->select($sql_select);
	//print_r($sql);
	if($sql)
	{
	//$i=0;
	for($j=0;$j<count($sql);$j++)
	 { 
		$proid=$sql[$j]['intprodid'];
		//echo $proid;
		 //$i=$i+1;
		  ?>
		  
  <tr class="<?php echo ($j%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';" onMouseOut="this.className='<?php echo ($j%2==0)?"Hrnormal":"Hralter"; ?>';">
				<td align="center"><?php echo $proid;?></td>
              <td align="center">
			  <?php
			  /*$sql6="select * from tblproddesc where intid = '$proid'"; 
			  $resname = $obj_db->select($sql6);
			  if(count($resname)>0)
			  {
				echo $resname[0]['varprodname'];
			   }	*/
					//$proid = 	
					echo $sql[$j]['varprodname'] 		  		
			  ?>	
			  </td>
              <td align="center"><img src="../images/product/<?php echo $sql[$j]['intproddefaultimg'];?>" title="'<?php echo $sql[$j]['varprodname'];?>'" alt="<?php echo $sql[$j]['varprodname'];?>"/></td>
			  
			  
			  
			  <td align="center"><a Title="Click here to Add Product to Specials" href="addtospecial.php?proid=<?php echo $proid;?>" class="ab">Add Specials</a></td>
			  <td align="center"><a Title="Click here to see Product Images" href="productimages.php?proid=<?php echo $proid;?>" class="ab">Images</a></td>
			  <td align="center"><a Title="Click here to view Gift Ideas" href="addtogift.php?proid=<?php echo $proid;?>" class="ab">Add to Gift Idea</a></td>
			  <td align="center"><a Title="Click here to Add Product Related Products" href="addtorelated.php?proid=<?php echo $proid;?>" class="ab">Add Related Product</a></td>
			
			  <td align="center"><table border="0" cellspacing="0" cellpadding="0" align="center">
				  <tr>
		<?php 
					if($sql[$j]['intstatus']==0)
					{
						
						echo "<td><a Title='Click here to Show Product' class='aa' href='product.php?status=0&s=0&pid=$proid'>Show</a></td>";		
					}
					if($sql[$j]['intstatus']==1)
					{
						
						echo "<td><a Title='Click here to Hide Product' class='aa' href='product.php?status=1&s=1&pid=$proid'>Hide</a></td>";
					}
				?>
				</tr></table></td>
				<td><a href="product.php?fid=<?php echo $proid;?>&action=6&sort=<?php echo $sql[$j]['intordered'];?>" class="aa">Ascending</a></td>
				<td><a href="product.php?fid=<?php echo $proid;?>&action=7&sort=<?php echo $sql[$j]['intordered'];?>" class="aa">Descending</a></td>
				<td align="center"><?php 
				$adm=$sql[$j]['varedited'];
				$sqla="select varadminfname from tbladmin where intid='$adm'";
				$resa=$obj_db->select($sqla);
				echo $resa[0]['varadminfname'];
				?></td>
              <td align="center"><a class="link" Title="Click here to Edit" href="product.php?script=editproduct&amp;a=2&amp;intid=<?php echo $proid;?>"><img src="images/edit.bmp" border="0"/></a></td>
              <td align="center"><a Title="Click here to Delete" class="link" href="product.php?a=3&amp;intid=<?php echo $proid;?>" onClick="return confirm('Are you sure to delete this record ?');"><img src="images/delete.bmp" border="0"/></a></td>
  </tr>
            <?php 
		}
		?>
            <tr >
              <td colspan="13" ><div align="center">
                  <?php
pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page);
?>
              </div></td>
            </tr>
            <?php
	}	
   ?>
</table>
		
		
		</td>
      </tr>
    </table>
    <?php
}}

?></td>
      <td width="3%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="3"><?php include("inc/bottom.php");?></td>
  </tr>
</table>